package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.department.*;
import com.boatAnchorAssistant.pojo.vo.department.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 *   web/部门
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 *
 */
@RestController
@RequestMapping("/department/web")
public class DepartmentWebController {

    private final DepartmentService service;

    public DepartmentWebController(DepartmentService service) {
        this.service = service;
    }


    /**
     * 创建部门
     * @param param
     * @return
     */
    @PostMapping("/createDepartment")
    public ApiResult createDepartment(@RequestBody @Valid CreateDepartmentParam param) {
        service.createDepartment(param);
        return ApiResult.ok();
    }


    /**
     * 修改部门
     * @param param
     */
    @PutMapping("/editDepartment")
    public ApiResult editDepartment(@RequestBody @Valid EditDepartmentParam param) {
        service.editDepartment(param);
        return ApiResult.ok();
    }

    /**
     * 移除部门
     * @param id
     */
    @DeleteMapping("/deleteDepartment")
    public ApiResult removeDepartment(@RequestParam("id") Long id) {
        service.removeDepartment(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用部门
     * @param id
     */
    @GetMapping("/enabledDepartment")
    public ApiResult enabledDepartment(@RequestParam("id") Long id) {
        service.enabledDepartment(id);
        return ApiResult.ok();
    }

    /**
     * 获取部门详情
     * @param id
     * @return
     */
    @GetMapping("/getDepartment")
    public ApiResult<GetDepartmentVo> getDepartment(@RequestParam("id") Long id) {
        GetDepartmentVo vo = service.getDepartment(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取部门列表
     * @param param
     * @return
     */
    @PostMapping("/getDepartmentList")
    public ApiResult<PageResult<GetDepartmentListVo>> getDepartmentList(@RequestBody GetDepartmentListParam param) {
        PageResult<GetDepartmentListVo> result = service.getDepartmentList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取部门下拉列表
     *
     * @return
     */
    @PostMapping("/getDepartmentDownList")
    public ApiResult<List<GetDepartmentDownListVo>> getDepartmentDownList(@RequestBody(required = false) @Valid GetDepartmentDownListParam param) {
        List<GetDepartmentDownListVo> list = service.getDepartmentDownList(param);
        return ApiResult.ok(list);
    }



    /**
     * 设置部门负责人
     * @return
     */
    @PostMapping("/setDepartmentLinkman")
    public ApiResult setDepartmentLinkman(@RequestBody @Valid SetDepartmentLinkmanParam param){
        service.setDepartmentLinkman(param);
        return ApiResult.ok();
    }


}

